package com.qf.shiro2204.config;

import com.qf.shiro2204.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 通过配置类让自定义的filter生效
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<MyFilter> myFilterFilterRegistrationBean(MyFilter myFilter){

        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>();
        // 过滤所有请求
        registrationBean.addUrlPatterns("/*");
        // 设置处理请求的filter对象
        registrationBean.setFilter(myFilter);

        // 设置filter的位置 ,数越小越考前
        registrationBean.setOrder(Integer.MIN_VALUE);

        return registrationBean;

    }

}
